package com.llc.mall.user.application.query.service.impl;

import com.llc.mall.user.application.query.service.UserAddrQueryService;
import com.llc.mall.user.infrastructure.persist.mapper.UserAddrMapper;
import com.llc.mall.user.interfaces.vo.UserAddrVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class UserAddrQueryServiceImpl implements UserAddrQueryService {

    @Autowired
    private UserAddrMapper userAddrMapper;

    @Override
    public List<UserAddrVo> list(Long userId) {
        return userAddrMapper.list(userId);
    }

    @Override
    public UserAddrVo getUserAddrByUserId(Long addrId, Long userId) {
        // 获取用户默认地址
        if (addrId == 0) {
            return userAddrMapper.getUserDefaultAddrByUserId(userId);
        }
        return userAddrMapper.getByAddrId(addrId,userId);
    }
}
